<?php
$service = new sqlServicesFunctions();
$allAnrede = $service->getAnrede();
$schulungen = $service->getSchulungen();
$zeiten = $service->getZeiten();
$allTitel = $service->getTitel();
?>

<html lang="de">
<head>
<meta charset="utf-8">

<link rel="stylesheet"
	href="jquery-ui-1.10.4.custom/development-bundle/themes/custom-theme/jquery-ui.css">
<link rel="stylesheet" href="style.css">
<script>

	$(function() {
		$('#formular').hide();
    	$( "input[type=button], a, button" )
      	.button()
      	.click(function( event ) {
        	event.preventDefault();
      	});
	});
</script>
</head>
<body>
<script type="text/javascript">

function auswahlRowA(btn, id) {
	var row = btn.parentNode.parentNode;
	var cells = row.cells;
	$('#btnID')				.val(btn);
	$('#anredeSelectMA')	.val(cells[0].innerHTML);
	$('#titelSelectMA')		.val(cells[1].innerHTML);
	$('#vornameInputMA')	.val(cells[2].innerHTML); 
	$('#nameInputMA')		.val(cells[3].innerHTML); 
	$('#strasseInputMA')	.val(cells[4].innerHTML); 
	$('#hausnrInputMA')		.val(cells[5].innerHTML);
	$('#plzInputMA')		.val(cells[6].innerHTML); 
	$('#ortInputMA')		.val(cells[7].innerHTML); 
	$('#telefonInputMA')	.val(cells[8].innerHTML); 
	$('#emailInputMA')		.val(cells[9].innerHTML); 
	$('#schulungSelectMA')	.val(cells[10].innerHTML); 
	$('#zeitSelectMA')		.val(cells[11].innerHTML); 
	$('#notizTextMA')		.val(cells[12].innerHTML); 
	$('#id')				.val(id);
	$('#formular').show();
}

function speichernA() {

	var btn = document.getElementById('btnID').value;
	var row = btn.parentNode.parentNode;
	var cells = row.cells;
	cells[0].innerHTML = $('#anredeSelectMA').val();
	cells[1].innerHTML = $('#titelSelectMA').val();
	cells[2].innerHTML = $('#vornameInputMA').val();
	cells[3].innerHTML = $('#nameInputMA').val();
	cells[4].innerHTML = $('#strasseInputMA').val();
	cells[5].innerHTML = $('#hausnrInputMA').val();
	cells[6].innerHTML = $('#plzInputMA').val();
	cells[7].innerHTML = $('#ortInputMA').val();
	cells[8].innerHTML = $('#telefonInputMA').val();
	cells[9].innerHTML = $('#emailInputMA').val();
	cells[10].innerHTML = $('#schulungSelectMA').val();
	cells[11].innerHTML = $('#zeitSelectMA').val();
	cells[12].innerHTML = $('#notizTextMA').val();

	var id 				= $('#id').val(); 

	$.getScript("classes/AJAXHelper.js", function() {
		doAJAX("updateAnmeldung", cells[0].innerHTML+","
				+cells[1].innerHTML+","
				+cells[2].innerHTML+","
				+cells[3].innerHTML+","
				+cells[4].innerHTML+","
				+cells[5].innerHTML+","
				+cells[6].innerHTML+","
				+cells[7].innerHTML+","
				+cells[8].innerHTML+","
				+cells[9].innerHTML+","
				+cells[10].innerHTML+","
				+cells[11].innerHTML+","
				+cells[12].innerHTML+","
				+cells[13].innerHTML+","
				+cells[14].innerHTML+","
				+cells[15].innerHTML+","
				+id, function() {
					if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
						if(xmlhttp.responseText){
							alert(xmlhttp.responseText);
						}
					}
				});
	});
	
	verstecken();
}

function verstecken() {
		$('#formular').hide();
}


function deleteRowA(btn, id) {
	if(confirm(unescape("M%F6chten Sie diese Anmeldung l%F6schen%3F"))){
		var row = btn.parentNode.parentNode;
		var cells = row.cells;

		$.getScript("classes/AJAXHelper.js", function() {
			doAJAX("deleteAnmeldungPerson", cells[0].innerHTML+","
					+cells[1].innerHTML+","
					+cells[2].innerHTML+","
					+cells[3].innerHTML+","
					+cells[4].innerHTML+","
					+cells[5].innerHTML+","
					+cells[6].innerHTML+","
					+cells[7].innerHTML+","
					+cells[8].innerHTML+","
					+cells[9].innerHTML+","
					+cells[10].innerHTML+","
					+cells[11].innerHTML+","
					+cells[12].innerHTML+","
					+cells[13].innerHTML+","
					+id, function() {
						if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
							if(xmlhttp.responseText){
								alert(xmlhttp.responseText);
							}
						}
					});
		});
		var row = btn.parentNode.parentNode;
	  	row.parentNode.removeChild(row);	
	};
}
</script>
<div id=><span id="hinweismeldung"></span>

<div id="formular">
<table id="anmeldungEinstellenTabelle" style="width: 100%">
	<tr>
		<td id="id" style="display:none"></td>
		<td><label style="width: 100%">Anrede</label></td>
		<td><select id="anredeSelectMA" style="width: 100%">
			<?php
				while ($anrede = $allAnrede->next()) {
					echo '<option value="' . $anrede['ABezeichnung'] . '">' . $anrede['ABezeichnung'] . '</option>';
				}
			?>
		</select></td>
		<td>Titel</td>
		<td><select id="titelSelectMA" style="width: 100%">
		<?php
			while ($titel = $allTitel->next()) {
				echo '<option value="' . $titel['TBezeichnung'] . '">' . $titel['TBezeichnung'] . '</option>';
			}
		?>
		</select></td>
	</tr>
	<tr>
		<td><label style="width: 100%">Vorname</label></td>
		<td><input id="vornameInputMA" name="vornameInput" type="text"
			style="width: 100%" onclick="this.select();"></input></td>
		<td><label style="width: 100%">Name</label></td>
		<td><input id="nameInputMA" style="width: 100%" onclick="this.select();"></input></td>
	</tr>
	<tr>
		<td><label style="width: 100%">Telefon</label></td>
		<td><input id="telefonInputMA" style="width: 100%"
			onclick="this.select();"></input></td>
		<td nowrap><label style="width: 100%">E-Mail</label></td>
		<td><input id="emailInputMA" style="width: 100%"
			onclick="this.select();"></input></td>
		<!-- td><label style="width: 100%">Fax</label></td>
		<td><input id="faxInput" style="width: 100%" onclick="this.select();"></input></td -->
	</tr>
	<tr>
		<td><label style="width: 100%">Stra&szlig;e</label></td>
		<td><input id="strasseInputMA" style="width: 100%"
			onclick="this.select();"></input></td>
		<td><label style="width: 100%">HausNr</label></td>
		<td><input id="hausnrInputMA" style="width: 100%" align="right"
			id="spinner" name="value"></td>
	</tr>
	<tr>
		<td><label style="width: 100%">PLZ</label></td>
		<td><input id="plzInputMA" style="width: 100%" onclick="this.select();"></input></td>
		<td><label style="width: 100%">Ort</label></td>
		<td><input id="ortInputMA" style="width: 100%" onclick="this.select();"></input></td>
	</tr>
	<tr>
		<td valign="top"><label style="width: 100%">Schulung</label></td>
		<td valign="top"><select id="schulungSelectMA" style="width: 100%">
		<?php
		while ($schulung = $schulungen->next()) {
			echo '<option value="' . $schulung['Beschreibung'] . '">' . $schulung['Beschreibung'] . '</option>';
		}
		?>
		</select></td>
		<td valign="top"><label style="width: 100%">Zeit</label></td>
		<td valign="top"><select id="zeitSelectMA" style="width: 100%">
		<?php
		while ($zeit = $zeiten->next()) {
			echo '<option value="' . $zeit['Bezeichnung'] . '">' . $zeit['Bezeichnung'] . '</option>';
		}
		?>
		</select></td>
		<td valign="top"><label style="width: 100%">Notiz</label></td>
		<td><textarea id="notizTextMA" style="width: 100%" rows="5" cols="15"
			onclick="this.select();"></textarea></td>
		<td></td>
		<td>
		<button style="width: 100%" onclick="verstecken()">abbrechen</button>
		<br>
		<input type="button" style="width: 100%"
			onclick="speichernA('anmeldeTable')" value="speichern"></td>
	</tr>
	<tr>
		<td id="btnID" style="display:none">
		</td>
	</tr>
</table>
</div>

<table class="table" id="alleAnmeldungenTable">
	<tr>
		<td>Anrede</td>
		<td style="display:none">Titel</td>
		<td>Vorname</td>
		<td>Name</td>
		<td>Stra&szlig;e</td>
		<td>HausNr</td>
		<td>PLZ</td>
		<td>Ort</td>
		<td>Telefonnr</td>
		<td style="display:none">Fax</td>
		<td style="display:none">EmailAdresse</td>
		<td>Schulung</td>
		<td>Zeit</td>
		<td>Notiz</td>
		<td>Eingangsdatum</td>
		<td style="display:none">idAnmeldung</td>
		<td style="display:none">idTeilnehmer</td>
		<td style="display:none">idArzt</td>
		<td></td>
	</tr>
	<?php
	$daten = $service->getAnmeldungen(Session::getIDPerson());
	$i = 0;
	while ($datensatz = $daten->next())
	{
		echo '<tr>';
		echo '<td>'							. $datensatz['ABezeichnung'] 	. '</td>';
		echo '<td style="display:none">' 	. $datensatz['TBezeichnung'] 	. '</td>';
		echo '<td>' 						. $datensatz['Vorname'] 		. '</td>';
		echo '<td>' 						. $datensatz['Name'] 			. '</td>';
		echo '<td>' 						. $datensatz['Strasse'] 		. '</td>';
		echo '<td>' 						. $datensatz['Hausnummer'] 		. '</td>';
		echo '<td>' 						. $datensatz['PLZ'] 			. '</td>';
		echo '<td>' 						. $datensatz['Ort'] 			. '</td>';
		echo '<td>' 						. $datensatz['Telefonnummer'] 	. '</td>';
		echo '<td style="display:none">' 	. $datensatz['Faxnummer'] 		. '</td>';
		echo '<td style="display:none">' 	. $datensatz['EMailAdresse'] 	. '</td>';
		echo '<td>' 						. $datensatz['Schulung'] 		. '</td>';
		echo '<td>' 						. $datensatz['Zeit'] 			. '</td>';
		echo '<td>' 						. $datensatz['Notiz'] 			. '</td>';
		echo '<td>' 						. $datensatz['EingangsDatum']   . '</td>';
		echo '<td  style="display:none">' 	. $datensatz['idAnmeldung'] 	. '</td>';
		echo '<td  style="display:none">' 	. $datensatz['idTeilnehmer'] 	. '</td>';
		echo '<td  style="display:none">' 	. Session::getIDPerson() 		. '</td>';
		echo '<td>
				<input type="button" style="width: 100%"
				onclick="deleteRowA(this,' . Session::getIDPerson() . ')" value="L&ouml;schen">
				<br>
				<input type="button" style="width: 100%"
				onclick="auswahlRowA(this,' . Session::getIDPerson() . ')" value="&Auml;ndern"></td>';
		echo '</tr>';
		$i++;
	}
	?>
</table>
</div>

</body>
</html>
